﻿using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using zhangmenren.IService;
using zhangmenren.Models;
using zhangmenren.Models.ViewModle;
using zhangmenren.Repository;
using System.Linq;
using zhangmenren.Models.Enums;

namespace zhangmenren.Service
{
    public class WorksService : IWorksService
    {
        private WorksRepository WorksRepository = new WorksRepository();
        public Task<int> Add(WorksEntity entity)
        {
            return Task.FromResult(WorksRepository.Add(entity));
        }

        public Task<int> Del(int id)
        {
            return Task.FromResult(WorksRepository.Del(id));
        }

        public Task<int> EditState(int id, bool state)
        {
            return Task.FromResult(WorksRepository.EditState(id,state));
        }

        public Task<WorksModel> FindById(int id)
        {
            return Task.FromResult(WorksRepository.FindById(id).FirstOrDefault());
        }

        public Task<int> IsXianShi(int id, bool isrecommend)
        {
            return Task.FromResult(WorksRepository.IsXianShi(id, isrecommend));
        }

        public Task<IEnumerable<WorksModel>> Selelct(int index, int page, string key)
        {
            return Task.FromResult(WorksRepository.Select(index,page,key));
        }

		/// <summary>
		/// 根据掌门id进行查找
		/// </summary>
		/// <param name="zmid"></param>
		/// <returns></returns>
		public Task<IEnumerable<WorksEntity>> FindByZMId(int zmid)
		{
			return Task.FromResult(WorksRepository.FindByZMId(zmid));
		}

		public Task<IEnumerable<WorksModel>> SelelctTuiJian()
        {
            return Task.FromResult(WorksRepository.SelectTuiJian());
        }

        public Task<int> EditSort(int id, int sort)
        {
            return Task.FromResult(WorksRepository.EditSort(id,sort));
        }

        public Task<IEnumerable<WorksModel>> Selelct(WorkType type, string key,int num=0)
        {
            return Task.FromResult(WorksRepository.Select(type,key,num));
        }
    }
}
